import { _decorator, Component, Label, Node, Sprite } from 'cc';
import { ConfigKey, PopView } from '../manager/AppControll';
import { PopManager } from '../manager/PopManager';
import { GameData } from '../system/GameData';
import { DataHelper } from '../system/DataHelper';
import { SystemMessage } from '../pop/SystemMessage';
import { SoundManager } from '../manager/SoundManger';
const { ccclass, property } = _decorator;

@ccclass('SignBtn')
export class SignBtn extends Component {
    private interval = 20;
    private cur = 0;
    private mNdPoint: Node = null;
    private mBIsLock: boolean = true;
    private mNdLock: Node = null;
    protected onLoad(): void {
        this.mNdPoint = this.node.getChildByName("yellowPoint");
        this.mNdLock = this.node.getChildByName("unlockText");
        this.node.on(Node.EventType.TOUCH_END, this.OnTouch, this);
        this.mBIsLock = GameData.playerData.Honor < Number.parseInt(DataHelper.GetConfigByKey(ConfigKey.sevenSign).value);
        if (this.mBIsLock == false) {
            this.mNdLock.active = false;
            this.node.getComponent(Sprite).grayscale = false;
        } else {
            this.mNdLock.active = true;
            this.node.getComponent(Sprite).grayscale = true;
        }
    }

    OnTouch() {
        SoundManager.Instance<SoundManager>().PlayEffect(GameData.btnClick)
        if (this.mBIsLock) {
            PopManager.Instance<PopManager>().ShowPop(PopView.systemMessage, (node) => {
                node.getComponent(SystemMessage).InitContent("尚未达到解锁条件")
            })
            return;
        }
        PopManager.Instance<PopManager>().ShowPop(PopView.sevenSignIn);
    }

    protected update(dt: number): void {
        this.cur++;
        if (this.cur % this.interval == 0) {
            if (this.mBIsLock == true) {
                this.mBIsLock = GameData.playerData.Honor < Number.parseInt(DataHelper.GetConfigByKey(ConfigKey.sevenSign).value);
                if (!this.mBIsLock) {
                    this.mNdLock.active = false;
                    this.node.getComponent(Sprite).grayscale = false;
                }
            }
            GameData.GetCurSignIn();
            if (GameData.playerData.signInCount < 1 && this.mBIsLock == false) {
                this.mNdPoint.active = true;
            } else {
                this.mNdPoint.active = false;
            }

        }
    }
}


